package com.simon.hse.activity.contractor;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.adapter.CommonAdapter;
import com.simon.hse.adapter.CommonEmptyAdapter;
import com.simon.hse.adapter.CommonViewHolder;
import com.simon.hse.http.entity.ExaminRecordListOutput;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 出入场工具管理
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_add_utils)
public class AddUtilsActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;
    @ViewInject(R.id.tv_add_utils)
    TextView tv_add_utils;

    @ViewInject(R.id.ll_chuchang_num)
    LinearLayout ll_chuchang_num;
    @ViewInject(R.id.recyclerview)
    RecyclerView mRecyclerView;

    private CommonAdapter mCommonEmptyAdapter;

    private List<String> listData = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTv_common_title.setText("出入场工具管理");
        initRecyclerView();
    }

    private void initRecyclerView() {
        LinearLayoutManager llm = new LinearLayoutManager(AddUtilsActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        mCommonEmptyAdapter = new CommonAdapter(AddUtilsActivity.this, R.layout.layout_utils_details_record, listData);
        mCommonEmptyAdapter.setItemDataListener(new CommonAdapter.ItemDataListener<String>() {
            @Override
            public void setItemData(CommonViewHolder holder, String dataBean) {
                ImageView iv_delete = holder.getView(R.id.iv_delete);
                iv_delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        listData.remove(holder.getPosition());
                        mCommonEmptyAdapter.notifyDataSetChanged();
                    }
                });
            }
        });
        mCommonEmptyAdapter.setHasStableIds(true);
        mRecyclerView.setAdapter(mCommonEmptyAdapter);
    }

    @Event(value = {R.id.iv_common_left, R.id.tv_add_utils, R.id.tv_train_record_cancel, R.id.tv_train_record_confirm})
    private void clickButton(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.tv_add_utils:
                listData.add("");
                mCommonEmptyAdapter.notifyDataSetChanged();
                break;
            case R.id.tv_train_record_cancel:
                finish();
                break;
            case R.id.tv_train_record_confirm:
                finish();
                break;
        }
    }
}
